<template>
  <view>
    <public-header :title="title" :isBack="isBack"></public-header>
    <u-loading-page :loading="true" v-if="!listV2Loaded"></u-loading-page>

    <view class="g-main-content">
      <view class="g-main-body">
        <view class="g-main-body-left">
          <rFilter ref="filterTabs" :inListType="config.listLayout" :labelPos="'top'"
            v-if="tabs.length > 0 && gridHeader.length > 0 && listV2Loaded" :tabs="tabs" :srv="config.serviceName"
            :cols="gridHeader" @on-change="onFilterChange"></rFilter>
          <view class="g-main-body-left-list">
            <scroll-view class="scroll-left " style="height:100% ;" @refresherrefresh="reload"
              @refresherrestore="onRestore" :refresher-enabled="refresherEnabled"
              :refresher-triggered="refresherTriggered" :show-scrollbar="true" :scroll-y="true" @scrolltoupper="upper"
              @scrolltolower="lower" @scroll="scroll">
              <view class="" style="height: 50vh;display: flex;align-items: center;justify-content: center;"
                v-if="loadMoreState==='noMore' && listData.length===0">
                <u-empty mode="list" text="暂无数据"></u-empty>
              </view>
              <uni-list :border="false" class="show-y-scroll-bar">
                <uni-list-item :border="false" :class="detailData && item.id == detailData.id ? 'avtive' : ''"
                  v-for="(item,index) in listData" :key="index" :clickable="true" @click="onItemChecked(item)">
                  <template v-slot:body class="">
                    <view class="list-item-inline">
                      <uni-row class="demo-uni-row margin-bottom-xs">
                        <uni-col :span="16">
                          单号：{{item.order_no}}
                        </uni-col>
                        <uni-col class="text-right text-blod" :span="8">
                          {{item.order_state}}
                        </uni-col>
                      </uni-row>
                      <uni-row class="">
                        <uni-col :span="12">
                          {{item.create_time}}
                        </uni-col>
                        <uni-col class="text-right  text-blod" :span="12">
                          <text class="">
                            {{setMoneyStr(item.pay_amount)}}
                          </text>
                          <text class="text-red margin-left"
                            v-if="item.refund_amount">(退款:{{item.refund_amount}})</text>
                        </uni-col>
                      </uni-row>
                    </view>
                  </template>
                </uni-list-item>
              </uni-list>
            </scroll-view>
          </view>
        </view>

        <view class="g-main-body-right" v-if="detailLoad &&orderchildloaded">
          <view class="member-detail bg-white padding-sm list-detail show-y-scroll-bar"
            v-if="listData.length > 0">
            <order-detail :orderDetailHeader="orderDetailHeader" :faceDataFields="faceDataFields" :detailData="detailData" :orderDetailData="orderDetailData" :orderUseActHeader="orderUseActHeader" :actDetailList="actDetailList" :refundDetailData="refundDetailData" :refundDetailHeader="refundDetailHeader"></order-detail>
            
            
            <uni-row :name="row.showType + index" v-for="(row,index) in columnRowConfigRun" :key="index">
              <uni-section :ken="row.showType + index" :title="row.section" type="line"
                v-if="(row.section && row.section !== '退货明细') || (row.section && row.section == '退货明细' && refundDetailData.length > 0) ">
                <uni-row>
                  <uni-col :name="col+l" class="bg-white"
                    v-if="(row.showType == 'childlist' && row.columns.length > 0) || row.showType == 'formitem'"
                    :span="['pay_amount','order_total_amount','pay_amount_str','order_total_amount_str','pay_amount_strs'].includes(col)?24:row.colspan"
                    v-for="(col,l) in row.columns" :key="l">

                    <view class="form-item"
                      v-if="col.indexOf('child|') == -1 && col !== '#children'&&(getColumnvalue(col,'value')||row.section !== '合计信息')">
                      <text :column="col" :class="{'text-red':'pay_amount'===col||'pay_amount_str'===col}"
                        class="text-bold form-item-label">{{getColumnvalue(col,'label')}}:</text>
                      <text class="form-item-coutent"
                        v-if="config.serviceName == 'srvretail_store_order_select' && col == 'order_state'">
                        <uni-tag :inverted="true" :text="getColumnvalue(col,'value')"
                          :type="getColumnvalue(col,'value') == '已结账'?'primary' : 'error'" />
                      </text>
                      <text class="form-item-coutent" :class="{'text-red':'pay_amount'===col||'pay_amount_str'===col}"
                        v-else>{{getColumnvalue(col,'value')||'--'}}</text>
                    </view>

                    <uni-table class="retail-list" border stripe emptyText="暂无数据"
                      v-if="orderchildloaded&&row.showType == 'childlist' && orderchildloaded && col.indexOf('child|srvretail_order_detail_select') !== -1">
                      <!-- 表头行 -->
                      <uni-tr v-if="orderDetailHeader.length > 0">
                        <uni-th :width="100" align="center" v-if="headCol.in_list === 1"
                          v-for="(headCol,index) in orderDetailHeader" :key="index">
                          {{headCol.label}}
                        </uni-th>
                      </uni-tr>
                      <!-- 表格数据行 -->
                      <uni-tr v-for="(dataRow,index) in orderDetailData" :key="index" v-if="orderDetailData.length > 0">
                        <uni-td v-if="headCol.in_list == 1" v-for="(headCol,i) in orderDetailHeader" :key="i">
                          <view class="table-td-text" @click="onItemClick(dataRow)">
                            {{setColumnText(dataRow[headCol.columns])}}
                          </view>
                        </uni-td>
                      </uni-tr>
                    </uni-table>

                    <uni-table class="retail-list" border stripe emptyText="暂无更多数据"
                      v-if="orderActLoaded&&row.showType == 'childlist' && col.indexOf('child|srvretail_order_use_act_select') !== -1">
                      <!-- 表头行 -->
                      <uni-tr v-if="orderUseActHeader.length > 0">
                        <uni-th :width="100" align="center" v-if="headCol.in_list === 1"
                          v-for="(headCol,index) in orderUseActHeader" :key="index">
                          {{headCol.label}}
                        </uni-th>
                      </uni-tr>
                      <!-- 表格数据行 -->
                      <uni-tr v-for="(dataRow,index) in actDetailList" :key="index" v-if="actDetailList.length > 0">
                        <uni-td v-if="headCol.in_list == 1" v-for="(headCol,i) in orderUseActHeader" :key="i">
                          <view class="table-td-text" @click="onItemClick(dataRow)">
                            {{setColumnText(dataRow[headCol.columns])}}
                          </view>
                        </uni-td>
                      </uni-tr>
                    </uni-table>

                    <uni-table class="retail-list" border stripe emptyText="暂无更多数据"
                      v-if="refundchildloaded&&row.showType == 'childlist' && col.indexOf('child|srvretail_refund_detail_select') !== -1 && refundDetailData.length > 0">
                      <!-- 表头行 -->
                      <uni-tr v-if="refundDetailHeader.length > 0">
                        <uni-th :width="150" align="center" v-if="headCol.in_list == 1"
                          v-for="(headCol,index) in refundDetailHeader" :key="index">
                          {{headCol.label}}
                        </uni-th>
                      </uni-tr>
                      <!-- 表格数据行 -->
                      <uni-tr v-for="(dataRow,index) in refundDetailData" :key="index"
                        v-if="refundDetailData.length > 0">
                        <uni-td :width="150" v-if="headCol.in_list == 1" v-for="(headCol,i) in refundDetailHeader"
                          :key="i">

                          <view class="table-td-text" @click="onItemClick(dataRow)">
                            {{setColumnText(dataRow[headCol.columns])}}
                          </view>
                        </uni-td>
                      </uni-tr>
                    </uni-table>
                  </uni-col>
                </uni-row>
              </uni-section>

              <uni-row v-if="!row.section">
                <uni-col class="bg-white "
                  v-if="(row.showType == 'datapanel' && row.columns.length > 0) || row.showType == 'formitem' || row.showType == 'childlist'"
                  :span="row.colspan" v-for="(col,l) in row.columns" :key="l">
                  <view class="form-item"
                    v-if="col !== '#children' && row.showType !== 'childlist'&&getColumnvalue(col,'value')">
                    <span class="text-bold form-item-label">{{getColumnvalue(col,'label')}}:</span><span
                      class="form-item-coutent"
                      :class="{'bg-red':'pay_amount'===col}">{{getColumnvalue(col,'value')}}</span>
                  </view>
                </uni-col>
              </uni-row>
            </uni-row>
          </view>

          <view v-if="fromButtons.length > 0 && detailData" class="button-group-box bg-white">
            <button @click="onFormButton(button)" style="margin-right: 2rem;" class="cu-btn g-button margin-tb-sm lg"
              v-for="(button,index) in fromButtons" :key="index"
              v-if="button.permission">{{button.button_name}}</button>
            <orderRefund @submit-refund-order="reload" type="part" :orderNo="detailData.order_no"
              v-if="service == 'srvretail_store_order_select' &&['已结账'].includes(detailData.order_state ) &&detailData.refund_amount<detailData.pay_amount&&detailData.discount_type!=='免单'">
            </orderRefund>
            <orderRefund @submit-refund-order="reload" :orderNo="detailData.order_no"
              v-if="service == 'srvretail_store_order_select' && detailData.order_state == '已结账'&&detailData.discount_type!=='免单'">
            </orderRefund>
          </view>
        </view>

      </view>
    </view>

  </view>
</template>

<script>
  import rFilter from '@/components/retail-list/retail-filter.vue'
  import orderRefund from "@/components/g-batch-update/refund-order.vue"
  import lockscreen from '@/common/mixins/lockscreen.js'
  import orderDetail from './order-detail.vue'
  export default {
    mixins: [lockscreen],
    data() {
      return {
        listPage: {
          pageNo: 1,
          rownumber: 10
        },
        refresherTriggered: false,
        refresherEnabled: true,
        loadMoreState: 'loading', //more/loading/noMore
        listV2Loaded: false, // 列表v2
        listV2Res: null,
        tabs: [],
        tabsBuild: false,
        filterCondition: [],
        relationCondition: null, // filter tabs 用户输入的查询条件
        listData: [], // 列表数据
        checkedItem: null, // 用户选择的行
        listLoadType: 'swipe',
        init_order_no: "",
        orderDetailHeader: [],
        orderDetailData: [],
        orderchildloaded: false,
        refundDetailHeader: [],
        refundDetailData: [],
        refundchildloaded: false,
        orderActLoaded: false,
        orderUseActHeader: [],
        actDetailList: [],
        orderNo: "",
        isBack: false,
        title: "", // 页面标题
        service: '',
        config: {
          serviceName: "",
          listLayout: "listAndDetail", // listAndDetail listAndFilter  list
          loadMoreType: "swipe", //swipe   check
          detailPath: "simple", //  simple  基础的； 或者配置页面路由 路由格式待定
          page: {
            pageNo: 1,
            rownumber: 20
          },
          listHeaders: [''],
          tabsType: "custom", //列表过滤条件 方式  custom 自定义 ， request  跟随v2配置
          custTabs: [{
            "colName": "order_no,goods_name",
            "type": "input",
            "inputType": "String",
            "parent": "",
            "is_count": false,
            "show_expr": {},
            "label": "订单信息",
            // "placeholder": "请输入商品名称/商品条码",
            "showLabel": false,
            "default": "",
            "colspan": 14,
            "showAllTag": false,
            "tags": []
          }, {
            "colName": "order_state",
            "type": "Select",
            "inputType": "enum", // enum dict fk
            "parent": "",
            "is_count": false,
            "show_expr": {},
            "label": "结算状态",
            "showLabel": false,
            "colspan": 10,
            "default": "",
            "showAllTag": true,
            "tags": [],
            "options": {}
          }, {
            "colName": "create_time",
            "type": "between",
            "inputType": "BetweenDate",
            "parent": "",
            "is_count": true,
            "show_expr": {},
            "label": "下单时间",
            "showLabel": false,
            "default": "",
            "colspan": 24,
            "showAllTag": true,
            "appendSearchButton": true
          }],
          tabs: {
            layout: 'inline', // 'inline'   block
          }
        },
        detailData: null,
        condition: [],
       
        columnRowConfig: [{
            columns: ['order_no', 'sales_clerk_name', 'order_state',
              'sales_clerk_staff_name', 'member_name', 'member_phone',
              "order_channel",
              "discount_reason_name",
              // 'remark'
            ],
            showType: "formitem", // usercard datapanel formitem
            section: "订单信息",
            label: true,
            colspan: 12, // 列
            buttons: [{
              button_name: "编辑",
              button_type: "edit",
              service: {
                select: "",
                update: "",
                add: "",
                delete: ""
              }
            }],
            children: []
          }, {
            columns: ['remark'],
            showType: "formitem", // usercard datapanel formitem
            section: "",
            label: true,
            colspan: 24, // 列
            buttons: [{
              button_name: "编辑",
              button_type: "edit",
              service: {
                select: "",
                update: "",
                add: "",
                delete: ""
              }
            }]
          }, {
            columns: ['child|srvretail_order_detail_select'],
            showType: "childlist", // usercard datapanel formitem childlist
            section: "商品信息",
            label: true,
            colspan: 24, // 列
            moreConfig: {
              custGridHeader: ['goods_name', 'sale_price', 'goods_num', 'discount_amount',
                'ctual_amount', 'refund_amount'
              ]
            },
            buttons: [{
              button_name: "编辑",
              button_type: "edit",
              service: {
                select: "",
                update: "",
                add: "",
                delete: ""
              }
            }]
          }, {
            columns: ['order_total_amount', 'discount_amount', 'member_discount',
              'discount_full_decrement',
              'discount_direct', 'change_price', 'discount_reduction_amount', 'free_discount_amount',
              'integral_deduction',
              'coupon_discount',
              'cash_reduction_amount', 'pay_amount'
            ],
            /*
             *sd
             */
            showType: "formitem", // usercard datapanel formitem childlist  202210290008
            section: "合计信息",
            label: true,
            colspan: 8, // 列
            buttons: [{
              button_name: "编辑",
              button_type: "edit",
              service: {
                select: "",
                update: "",
                add: "",
                delete: ""
              }
            }]
          }, {
            columns: ['create_time', 'payment_method', 'pay_time', 'concat_pay_amount', 'pay_flowing_water'],
            showType: "formitem",
            section: "交易信息",
            label: true,
            colspan: 12, // 列
          },
          {
            columns: ['child|srvretail_order_use_act_select'],
            showType: "childlist", // usercard datapanel formitem childlist
            section: "参与优惠/促销活动",

            label: true,
            colspan: 24, // 列
          },
          {
            columns: ['child|srvretail_refund_detail_select'],
            showType: "childlist", // usercard datapanel formitem childlist
            section: "退货明细",
            label: true,
            colspan: 24, // 列
            moreConfig: {
              custGridHeader: ['refund_no', 'goods_name', 'refund_num', 'refund_subtotal',
                'refund_reason', 'refund_state', 'modify_user_disp'
              ]
            },
            buttons: [{
              button_name: "编辑",
              button_type: "edit",
              service: {
                select: "",
                update: "",
                add: "",
                delete: ""
              }
            }]
          }
        ],
        faceDataFields: []
      }
    },
    computed: {
      conditionRun: function() {
        let cond = this.filterCondition || []
        return cond
      },
      rowButtons: function() {
        let btns = []
        return btns
      },
      gridHeader: function() {
        let cols = []
        if (Array.isArray(this.listV2Res.srv_cols)) {
          cols = this.listV2Res.srv_cols
        }
        cols = cols.filter((item) => item.in_list == 1)
        return cols
      },
      relationConditionRun: function() {
        let relationCondition = {}
        let filterRelation = this.relationCondition
        if (filterRelation && filterRelation.data && filterRelation.data.length > 0) {
          relationCondition['data'] = filterRelation['data']
          relationCondition['relation'] = "AND"
        }
        return relationCondition
      },
      detailLoad: function() {
        return this.detailData || false
      },
      columnRowConfigRun: function() {
        let config = this.deepClone(this.columnRowConfig)
        for (let item of config) {
          if (item.section == '合计信息') {
            // if (this.detailData.discount_type != "整单手动打折/改价") {
            item.columns = item.columns.filter((item) => {
              if (item === 'discount_reduction_amount' || item == 'discount_amount') {
                return false
              } else {
                return true;
              }
            })
            // }
          }

          if (item.section == '订单信息') {
            // console.log(this.detailData.discount_type, "==this.detailData.discount_type==")
            if (this.detailData.discount_type != "整单手动打折/改价" &&
              this.detailData.discount_type != "免单"
            ) {
              item.columns = item.columns.filter((item, index) => {
                if (item == "discount_reason_name") {
                  return false
                } else {
                  return true;
                }
              })
            }
          }



          let columns = item.columns
          item["childList"] = []
          if (item.showType == 'childlist' || item.showType == 'formitem') {
            for (let col of columns) {
              if (col.indexOf("child|") !== -1) {
                let colSplist = col.split('|')
                let childName = colSplist[1]
                item.childList.push(childName) // 根据 col 名指定格式配置 “col|service” 获取 子表service 

              }
            }
          }
        }
        return config
      },
      fromButtons: function() {
        let buttons = []
        if (this.v2Loaded) {
          // buttons = this.v2FieldsData._formButtons
        }
        if (this.service == 'srvretail_store_staff_select') {
          // buttons.push({
          // 	button_name:"设为营业员",

          // })
          buttons = this.v2FieldsData._formButtons
          buttons = buttons.concat(this.rowButtons)
          buttons = buttons.filter((item) => {
            let isOn = false
            if (item.permission && item.button_name == '设为营业员' && (this.data.business_status ==
                '否' || !this.data.business_status)) {
              isOn = true
            } else if (item.permission && item.button_name == '取消营业员' && this.data
              .business_status == '是') {
              isOn = true
            } else if (item.permission && item.button_name == '删除') {
              isOn = true
            } else if (item.permission && item.button_name == '编辑' && item.page_area !== '表格行按钮') {
              isOn = true
            }
            if (isOn) {
              return item
            }
          })
          console.log('buttons row', this.rowButtons)

        } else if (['srvretail_direct_order_detail_select', 'srvretail_store_order_select'].includes(this.service)) {
          buttons.push({
            "operate_service": "srvsys_order_print",
            "servcie_type": "operate",
            "page_type": "详情",
            "button_type": "customize",
            "operate_mode": "静默操作",
            "pre_confirm_msg": null,
            "client_type": "PC,APP",
            "tip_msg": null,
            "pre_data_handle": null,
            "effective": null,
            "biz_authority_cfg": null,
            "operate_params": {
              "data": [{
                "order_no": {
                  "value_type": "rowData",
                  "value_key": "order_no"
                }
              }]
            },
            "suffix_actions_service": null,
            "id": 287,
            "page_area": "底部按钮",
            "more_config": "{\r\n\t\"button_para\": {\r\n\t\t\"group_tag\": \"操作\"\r\n\t}\r\n}",
            "select_data": null,
            "suffix_actions_params": null,
            "seq": 100,
            "main_table": "bxretail_store_order",
            "suffix_actions": "refresh",
            "operate_type": "操作",
            "visible": "是",
            "button_name": "打印小票",
            "service_name": "srvsys_order_print",
            "service_view_name": "打印订单小票",
            "always_show": false,
            "permission": true,
            "application": "retail",
            "action_validate": null,
            "service": "srvretail_store_order_select",
            "is_public": false,
            "path_col": null,
            "proc_step": null,
            "disp_exps": "data.order_state=='已结账'"
          })
        } 
        return buttons

      }
    },
    components: {
      rFilter,
      orderRefund,
      orderDetail
    },
    methods: {
      onItemClick(e) {
        this.$set(this, 'checkedItem', e)
      },
      getV2Config(order_no) {
        this.page = this.listPage
        if (this.listV2Loaded) {
          this.getListData(1)
        } else {
          this.getServiceV2(this.service, 'select', 'list').then((res) => {
            this.listV2Res = res
            this.listV2Loaded = true
            if ( this.config.custTabs) {
              // 列表查询条件封装
              this.buildSections(this.config.custTabs, 'custom')
            }
            if (order_no) {
              setTimeout(() => {
                let tabsConds = this.$refs?.filterTabs?.buildConditions()
                this.relationCondition = tabsConds
                this.getListData()
              }, 200)
            } else {
              // 查询列表初始化数据
              this.getListData()
            }
          })
        }

      },
      getListData(pageNo) {
        let self = this
        console.log('getListData', pageNo, new Date().getTime())
        self.loadMoreState = 'loading'
        let srv = this.listV2Res.service_name
        let cond = this.conditionRun
        // let listType = type || 'swipe'
        let req = this.selectRequestObjs(srv, cond, null, this.relationConditionRun)
        // let req = this.selectRequestObjs(srv, cond,null,null)
        // delete this.listpage.total
        req["page"] = {
          "pageNo": this.listPage.pageNo,
          "rownumber": this.listPage.rownumber
        }
        if (pageNo) {
          req.page.pageNo = pageNo
        }

        if (this.listV2Loaded) {
          this.$fetch('select', srv, req).then((res) => {
            // this.refresherTriggered = false // 停止下拉刷新
            this.refresherEnabled = false
            setTimeout(() => {
              this.refresherEnabled = true
              this.refresherTriggered = false // 停止下拉刷新
            }, 100)
            console.log('refresherTriggered', this.refresherTriggered);
            if (res.success) {
              let listData = []
              if (pageNo !== 1 && pageNo !== null && pageNo !== undefined && this.listLoadType == 'swipe') {
                listData = this.listData.concat(res.data)
              } else {
                listData = []
                listData = res.data
              }
              this.listData = listData.map((item) => item)
              if (!this.detailData?.id) {
                self.onItemChecked(self.listData[0])
              } else {
                self.onItemChecked(this.detailData)
              }
              self.$set(self.listPage, 'pageNo', res.page.pageNo)
              self.$set(self.listPage, 'rownumber', res.page.rownumber)
              self.$set(self.listPage, 'total', res.page.total)
              if (res.page.pageNo * res.page.rownumber < res.page.total) {
                self.loadMoreState = "more"
              } else {
                self.loadMoreState = "noMore"
              }
              if (this.listData.length === 0) {
                // uni.showToast({
                //   title: '查找数据为空...',
                //   icon: 'none'
                // })
              }
            }
            uni.hideLoading()
          })

        }
      },

      reload() {
        this.$set(this.listPage, 'pageNo', 1)
        this.$set(this.listPage, 'rownumber', 10)
        delete this.listPage.total
        this.refresherTriggered = true
        console.log('refresherTriggered', this.refresherTriggered);
        this.getListData(this.listPage.pageNo)
        setTimeout(() => {
          this.refresherTriggered = false
        }, 3000)
        this.getchildDataV2()
      },

      onRestore() {
        this.triggered = 'restore'; // 需要重置
        console.log("onRestore");
      },
      upper(e) {
        console.log(e)
      },
      lower(e) {
        let self = this
        self.more = "loading"
        let page = self.deepClone(self.listPage)
        if ((page.pageNo * page.rownumber) < page.total) {
          self.getListData(page.pageNo + 1)
        } else {
          self.more = "noMore"
          uni.showToast({
            icon: "none",
            title: "没有更多了"
          })
        }
      },
      scroll(e) {
        // console.log(e)
      },
      onFilterChange(e) {
        let self = this
        if (e && self.$refs.filterTabs) {
          let tabsConds = self.$refs.filterTabs.buildConditions()
          self.relationCondition = tabsConds
        }
        self.getListData(1)
      },
      buildSections(tabs) { 
        let self = this
        let tab = {}
        let tabsData = []
          tabs.forEach((t, index) => {
            tab = {
              service: null,
              table_name: null,
              orders: null,
              conditions: null,
              seq: null,
              parent: null,
              label: null,
              list_tab_no: null,
              more_config: null,
              inputType: null,
              default: t.default
            }
            tab.service = t.service || ''
            tab._colName = t.colName.split(',') || null
            tab._type = t.type || null
            tab.inputType = t.inputType || null
            tab.colspan = t.colspan
            tab.label = t.label
            tab.placeholder = t.placeholder || t.type === 'Select' ? '请选择' : '请输入'
            tab.showAllTag = t.showAllTag || false
            tab.list_tab_no = t.list_tab_no || 'custom' + index
            tab._data = t
            tab.showLabel = t.showLabel
            tab.appendSearchButton = t.appendSearchButton || false
            tab._options = [] // 选项列表数据
            tab.option_list = t.options || null // 配置
            if (tab._colName) {
              let cols = tab._colName
              let srvCols = self.deepClone(self.listV2Res?.srv_cols||[])
              tab['_colSrvData'] = []
              for (let c = 0; c < cols.length; c++) {
                for (let cs = 0; cs < srvCols.length; cs++) {
                  if (cols[c] === srvCols[cs].columns) {
                    tab._colSrvData.push(srvCols[cs])
                  }
                }
              }
            }
             if (tab.inputType == 'enum' && tab._colSrvData.length > 0) {
              let colOptions = tab._colSrvData[0].option_list_v2
              tab._options = colOptions.map((item) => {
                let itemVal = {
                  text: item.label,
                  value: item.value
                }
                return itemVal
              }).filter(item => item.text !== '未结清')
              if (Array.isArray(tab._options) && tab._options.length > 0 && tab._options[0].text !== '全部') {
                tab._options = [{
                  text: '全部',
                  value: "_unlimited_"
                }, ...tab._options]
              }
            } else if (tab.inputType == '#staff#') {
              let colOptions = uni.getStorageSync('persistData').$staffList || []
              console.log('colOptions', colOptions)
              colOptions = colOptions.filter(item => item.staff_status == '在职')
              tab._options = colOptions.map((item) => {
                let itemVal = {
                  text: item.name,
                  value: item.staff_no
                }
                return itemVal
              })
            }
            tabsData.push(tab)
          })

        if (tabsData.length > 0 && !self.tabsBuild) {
          self.tabs = tabsData
          self.tabsBuild = true
        }
      },
      async getFaceData(e) {
        if (this.detailData?.id) {
          let srv = this.service
          if (this.detailData.order_state === '直接退款') {
            srv = 'srvretail_direct_order_detail_select'
            this.columnRowConfig[3].columns = ["order_total_amount_str", "discount_amount", "member_discount",
              "discount_full_decrement", "discount_direct", "change_price", "discount_reduction_amount",
              "free_discount_amount", "integral_deduction", "coupon_discount", "cash_reduction_amount",
              "pay_amount_str"
            ]
            this.columnRowConfig[4].columns = ["create_time", "payment_method", "pay_time", "pay_amount_strs",
              "pay_flowing_water"
            ]
          } else {
            srv = 'srvretail_store_order_select'
            this.columnRowConfig[3].columns = ['order_total_amount', 'discount_amount', 'member_discount',
              'discount_full_decrement',
              'discount_direct', 'change_price', 'discount_reduction_amount', 'free_discount_amount',
              'integral_deduction',
              'coupon_discount',
              'cash_reduction_amount', 'pay_amount'
            ]
            this.columnRowConfig[4].columns = ['create_time', 'payment_method', 'pay_time', 'concat_pay_amount',
              'pay_flowing_water'
            ]
          }
          this.service = srv
          this.config.serviceName = srv
          this.getServiceV2(srv, 'select', this.pageType).then((res) => {
            if (this.config.tabsType == 'custom' && this.config.custTabs) {
              // 列表查询条件封装
              this.buildSections(this.config.custTabs, 'custom')
            }
          })
          let cond = [{
            colName: 'id',
            ruleType: 'eq',
            value: this.detailData.id
          }]

          let req = this.selectRequestObjs(srv, cond, null)
          if(this.detailData.order_state === '直接退款'){
            let res = await this.$fetch('select', srv, req)
            if (res.success && res.data && res.data[0]) {
              this.detailData = res.data[0]
            }
          }
          this.getchildDataV2()
          this.onItemShowDetail()
          
        }
      },
      onItemChecked(e) {
        this.detailData = e
        uni.showLoading({
          title: '加载中',
          mask: true
        });
        this.$set(this, 'detailData', e)
        this.onItemShowDetail()
        this.getFaceData() 
      },
      onItemShowDetail(e) {
        this.faceDataFields = this.deepClone(this.setFieldsDefaultVal(this.listV2Res._fieldInfo, this.detailData))
      },
      getColumnvalue(col, type) {
        let field = null
        if(Array.isArray(this.faceDataFields)){
          field = this.faceDataFields.find(item => item.column === col)
        }
        let str = null;
        if (!field) {
          return
        }
        if (col && col.indexOf('child|') == -1 && col.indexOf('#child') == -1 && field[type]) {
          str = field[type]
        }

        if (col.indexOf('_disp') !== -1) {
          str = this.detailData[col]
        }
        if (str === 0 || field[type] === 0) {
          str = '0'
        }
        if (type === 'value' && str && field.col_type === 'Money') {
          str = Number(str)
          if (str < 0) {
            str = `-￥${Number(-str)}`
          } else if (str === 0) {
            if (col === 'pay_amount') {
              str = '￥0'
            }
          } else {
            str = `￥${Number(str)}`
          }
        }
        return str
      },
      onFormButton(btn, confirm) {
        this.avtiveButton = btn
        let submitRequest = false
        let req = [{
          "serviceName": btn.service_name,
          "data": [{
            "order_no": this.detailData.order_no
          }],
          "srvApp": "retail",
          "condition": []
        }]
        if (btn && btn.service_name == 'srvsys_order_print') {
          submitRequest = true
          req[0].data = [{
            "order_no": this.detailData.order_no
          }]
        }
        if (submitRequest) {
          this.$fetch('operate', btn.service_name, req).then((res) => {
            this.avtiveButton = null
            console.log(res)
            submitRequest = false
            if (res.success && res.data) {
              uni.showToast({
                icon: "none",
                title: '操作成功'
              })
              this.getFaceData()
            } else {
              uni.showToast({
                icon: "none",
                title: res?.msg || '操作失败'
              })
            }
          })
        }
      },
      getchildDataV2(e) {
        //显示加载框
        if ((this.service == 'srvretail_store_order_select' || this.service ==
          'srvretail_direct_order_detail_select') &&
          this.detailData) {
          this.getServiceV2('srvretail_order_detail_select', 'select', 'detaillist').then((res) => {
            console.log("res", res)
            this.orderDetailHeader = res._fieldInfo
            this.orderchildloaded = true
            this.getChildData('srvretail_order_detail_select', 'orderDetailHeader')
          })
          if (!this.orderActLoaded) {
            this.getServiceV2('srvretail_order_use_act_select', 'select', 'detaillist').then((res) => {
              this.orderUseActHeader = res._fieldInfo
              this.orderActLoaded = true
              this.getChildData('srvretail_order_use_act_select', 'orderUseActHeader')
            })
          } else {
            this.getChildData('srvretail_order_use_act_select', 'orderUseActHeader')
          }

          const service = 'srvretail_refund_detail_select'

          this.getServiceV2(service, 'select', 'detaillist').then((res) => {
            this.refundchildloaded = true
            this.$set(this, 'refundDetailHeader', res._fieldInfo)
            this.refundDetailHeader = res._fieldInfo
            this.getChildData(service, 'refundDetailHeader')
          })
        }
      },
      getChildData(srv, type) {
        let req = {}
        if (this.detailLoad) {
          req = {
            "serviceName": srv,
            "colNames": ["*"],
            "condition": [{
              "colName": "order_no",
              "ruleType": "eq",
              "value": this.detailData.order_no
            }],
            "page": {
              "pageNo": 1,
              "rownumber": 999
            }
          }
        }
        if (srv == 'srvretail_refund_detail_select') {
          if (srv && type && this.detailLoad) {
            this.$fetch('select', srv, req).then((res) => {
              if (res.success && Array.isArray(res.data)) {
                this.refundDetailData = res.data
                this.refundchildloaded = true
              }
              uni.hideLoading()
            })
          }
        } else if (srv == 'srvretail_order_detail_select') {
          this.refundDetailData = []
          if ((this.orderchildloaded) && srv && type && this.detailLoad) {
            this.$fetch('select', srv, req).then((res) => {
              if (res.success && res.data && res.data[0]) {
                let data = res.data
                this.orderDetailData = data.map(item => item)
                this.orderchildloaded = true
              }
              uni.hideLoading()
            })
          } else {
            this.getchildDataV2()
          }
        } else if (srv === 'srvretail_order_use_act_select') {
          this.actDetailList = []
          this.refundDetailData = []
          if ((this.orderActLoaded) && srv && type && this.detailLoad) {
            this.$fetch('select', srv, req).then((res) => {
              if (res.success && res.data && res.data[0]) {
                let data = res.data
                this.actDetailList = data.map(item => item)
                this.orderActLoaded = true
              }
              uni.hideLoading()
            })
          } else {
            this.getchildDataV2()
          }
        }

      }

    },
    onLoad(option) {
      //显示加载框
      if (option.order_no) {
        this.orderNo = option.order_no
        this.config.custTabs[0].default = option.order_no
        this.isBack = true
      }
      if (option.title) {
        this.title = option.title
      }
      uni.showLoading({
        title: '加载中',
        mask: true
      });
      this.service = option.srv
      this.config.serviceName = option.srv
      this.config.listLayout = option.listLayout
      this.getV2Config(option.order_no)
    },
  }
</script>

<style lang="scss" scoped>
  .g-main-content {
    height: calc(100vh - var(--window-top) - var(--window-bottom) - 6rem);
    overflow: hidden;
    .g-main-body {
      display: flex;
      flex-direction: row;
      height: 100%;

      .g-main-body-left {
        width: 30vw;
        height: 100%;
        // overflow: hidden;
        padding: 1rem;
        background-color: #fff;
        display: flex;
        flex-direction: column;

        .g-main-body-left-list {
          border-radius: 1rem;
          overflow: hidden;
          flex: 1;
        }

        .uni-list {
          background-color: transparent;
          padding-bottom: 5rem;

          &:before {
            display: none;
          }

          .uni-list-item__container {
            flex-direction: column;
          }

          .list-item-inline {
            width: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
          }

          .uni-list-item {
            color: #000;
            font-weight: 600;
            border-radius: 1rem;
            margin-bottom: 1rem;
            background-color: #f5f5f5;
            border: 1px solid #fff;
            overflow: hidden;

            &.avtive {
              border-color: $retail-color-primary;
              background-color: $retail-color-primary-light;
            }
          }
        }

        .scroll-left {
          background-color: #fff;
          padding: 1rem;
          padding-top: 0;

          ::v-deep .uni-scroll-view-refresher {
            background-color: transparent !important;
          }
        }
      }

      .g-main-body-right {
        padding: $padding;
        width: 70vw;
        height: 100%;
        // height: calc(100vh - 6rem);
        overflow: hidden;
        display: flex;
        flex-direction: column;

        .member-detail {
          flex: 1;
          overflow-y: scroll;
        }

        .form-item {
          padding: 2rem 1rem;
          display: flex;
          align-items: flex-start;

          &-coutent {
            word-break: break-all;
          }
        }

        // overflow-y: auto;
      }
    }

    .button-group-box {
      height: 8vh;
      width: 100%;
      align-items: center;
      justify-content: flex-end;
      display: flex;
      padding-right: 2rem;

      .g-button {
        height: 7vh;
        margin: 0;
        // font-weight: normal;
      }

      ::v-deep .button-group {
        padding: 0 1rem;

        .g-button {
          height: 7vh;
          margin: 0;
          text-align: center;
          justify-content: center;
          // font-weight: normal;
        }
      }
    }
  }
</style>
